package com.java.collection;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Objects;

public class LinkedListDemo {
    public static void main(String[] args) {
        //创建ArrayList
        LinkedList<String> linkedList = new LinkedList<>();
        //添加特定类型的数据
        linkedList.add("张三");
        linkedList.add("李四");
        linkedList.add("王五");
        linkedList.add(1,"老张");

        //在开头和结尾插上数据
        linkedList.addFirst("小李");
        linkedList.addLast("小杰");

        //在开头和结尾删除数据
        linkedList.removeFirst();
        linkedList.removeLast();
        System.out.println(linkedList.getFirst());
        System.out.println(linkedList.getLast());
        for (String obj : linkedList) {
            System.out.println("名字是：" +obj);
        }
    }
}